package belf.migrate.evaluate.model;

import belf.migrate.api.table.schema.ColumnMetaData;
import lombok.Data;

/**
 * 评估返回不兼容字段模型
 */
@Data
public class EvaluateColMapping {

    /**
     * 表名
     */
    private String table;
    /**
     * 列名
     */
    private String name;

    /**
     * 列类型
     */
    private String typeName;

    /**
     * 列长度
     */
    private Long length;

    /**
     * 列精度
     */
    private Integer precision;

    /**
     * 列标度
     */
    private Integer scale;

    /**
     * 时间精度
     */
    private Integer timePrecision;

    /**
     * 非空
     */
    private Integer nullable;

    /**
     * 默认值
     */
    private String defaultValue;

    public EvaluateColMapping(ColumnMetaData columnMetaData, boolean isTable) {
        if (isTable) {
            this.table = columnMetaData.getTableName();
            this.name = columnMetaData.getColumnName();
        }
        this.typeName = columnMetaData.getColumnTypeName();
        this.length = columnMetaData.getColumnDisplaySize();
        this.precision = columnMetaData.getPrecision();
        this.scale = columnMetaData.getScale();
        this.nullable = columnMetaData.getNullable();
        this.timePrecision = columnMetaData.getExtra() != null ? columnMetaData.getExtra().getDateTimePrecision() : null;
        this.defaultValue = columnMetaData.getExtra() != null ? columnMetaData.getExtra().getDefaultValue() : null;
    }
}
